home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / kcl.lha / ild / s.c < prev    next >
C/C++ Source or Header  |  1986-03-11  |  1KB  |  58 lines

  1. #include <stdio.h>
  2. #include <filehdr.h>
  3. #include <aouthdr.h>
  4. #include <scnhdr.h>
  5. #include <reloc.h>
  6. #include <syms.h>
  7.  
  8. int a[100];
  9.  
  10. main(argc, argv)
  11. int argc;
  12. char *argv[];
  13. {
  14.     FILE *fp;
  15.     struct scnhdr section;
  16.     int tsize, dsize, bsize, text_start;
  17.     char *text, *malloc();
  18.     char command[128];
  19.  
  20.     fp = fopen(argv[1], "r");
  21.     fseek(fp, sizeof(struct filehdr), 0);
  22.  
  23.     fread(§ion, sizeof(struct scnhdr), 1, fp);
  24.     tsize = section.s_size;
  25.     text_start = section.s_scnptr;
  26.     fread(§ion, sizeof(struct scnhdr), 1, fp);
  27.     dsize = section.s_size;
  28.     fread(§ion, sizeof(struct scnhdr), 1, fp);
  29.     bsize - section.s_size;
  30.     fclose(fp);
  31.  
  32.     printf("size: %d+%d+%d = %d\n", tsize, dsize, bsize,
  33.         tsize + dsize + bsize);
  34.     
  35.     text = malloc(tsize + dsize + bsize);
  36.  
  37.     sprintf(command, "ild %s %d %s tmp", argv[0], (int)text, argv[1]);
  38.     printf("%s\n", command);
  39.     if (system(command) != 0)    {
  40.         fprintf(stderr, "Can't relocate.\n");
  41.         exit(1);
  42.     }
  43.  
  44.     fp = fopen("tmp", "r");
  45.     fseek(fp, text_start, 0);
  46.     fread(text, 1, tsize + dsize, fp);
  47.     fclose(fp);
  48.  
  49.     a[10] = 123;
  50.  
  51.     (*(int (*)())text)();
  52. }
  53.  
  54. dummy()
  55. {
  56.     printf("What?\n");
  57. }
  58.